#ifndef GEOMETRY2D_H_INCLUDED
#define GEOMETRY2D_H_INCLUDED

#include <math.h>
class vector2D;
class line2D;
class segment2D;
class matrix2D;


class vector2D     ///point or vector
{
private:
    double x,y;
public:
    vector2D(double a=0, double b=0):x(a),y(b) {}
    vector2D& set(double xx, double yy) {x = xx, y = yy; return *this;}
    vector2D& operator+=(const vector2D& a) {x += a.x, y += a.y; return *this;}
    vector2D operator+(vector2D a) const {a.x += x, a.y += y; return a;}
    vector2D& operator-=(const vector2D& a) {x -= a.x, y -= a.y; return *this;}
    vector2D operator-(vector2D a) const {a.x = x - a.x, a.y = y - a.y; return a;}
    vector2D& operator*=(double k) {x *= k, y *= k; return *this;}
    vector2D operator*(double k) const {return vector2D(x * k, y * k);}
    vector2D perp() const {return vector2D(-y, x);}
    bool operator==(const vector2D& a) const {return x == a.x && y == a.y;}
    double operator*(const vector2D& a) const {return x * a.x + y * a.y;}     ///dot product
    double operator|(const vector2D& a) const {return x * a.y - y * a.x;}     ///cross product
    double vlen() const {return sqrt(x * x + y * y);}                         ///length of the vector2D
    double get_sin(const vector2D& a) {return ((*this) | a) / (this->vlen() * a.vlen());}
    double get_cos(const vector2D& a) {return ((*this) * a) / (this->vlen() * a.vlen());}
    bool decompose(const vector2D& a, const vector2D& b, double &m, double &n) const;
        ///m*a + n*b = *this, if a|b == 0, return false
};
#endif // GEOMETRY2D_H_INCLUDED
